using System;
using CStock;
using CUtil;
using System.Diagnostics;
namespace CStock
{
	
	//[System.Xml.Serialization.XmlRootAttribute("TradeCondition", Namespace="", IsNullable=false)]
    public class TraderFactory : Factory , ITraderFactory
    {

        ITrader trader;

        public TraderFactory()
        {
            
            trader = new Trader();
            trader.ID = "Default";

            this.stockObjectBase = trader as StockObjectBase;
        }

    


        public override bool Create_TestData()
        {
            base.Create_TestData();
            //profile...
            TradeSystemFactory tpf = new TradeSystemFactory();
            tpf.Create(this.trader.ID);
            tpf.Create_TestData();
            
            //portfolios
            AddDefaultPortfolio();
            this.trader.Orders = new Orders();
            this.trader.TradeSimulation.TradeSystem = tpf.StockObjectBase as ITradeSystem;

            
            return true;

        }
        public bool AddDefaultPortfolio()
        {
            this.trader.Portfolios = new Portfolios();

            IPortfolio portfolio = new Portfolio();
            PasswordGenerator defaultPwdGen = new PasswordGenerator(false);
            string myID = defaultPwdGen.Generate();

            portfolio.ID = this.trader.ID + myID;
            
            this.trader.Portfolios.Items.Add(portfolio);
            this.trader.Portfolio_Selected = portfolio;

            return true;
        }
        public bool AddDefaultSystem()
        {
            TradeSystemFactory tpf = new TradeSystemFactory();
            tpf.Create(this.trader.ID);
            this.trader.TradeSimulation.TradeSystem = tpf.StockObjectBase as ITradeSystem;
            //this.trader.Orders = new Orders();


            return true;


        }

        /// <summary>
        /// attention - new object variable for dataClass!!
        /// </summary>
        /// <returns></returns>
        public override bool DeSerialize()
        {
          
            if (base.DeSerialize())
            {
                this.trader = this.stockObjectBase as ITrader;
                return true;
            }

            return false;




        }
       
    }
}
